package com.example.ecommercemanagesystem.controller;


import com.example.ecommercemanagesystem.dto.MyMessage;
import com.example.ecommercemanagesystem.entity.Type;
import com.example.ecommercemanagesystem.service.TypeService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class TypeController {
    @Resource
    private TypeService typeService;

    public TypeService getTypeService() {
        return typeService;
    }

    public void setTypeService(TypeService typeService) {
        this.typeService = typeService;
    }

    /**
     * 获取所有类型
     * @param request
     * @return
     */
    @RequestMapping("/getAllType")
    public String getAllType(HttpServletRequest request) {
        List<Type> list = typeService.getAllType();
        request.setAttribute("list", list);
        return "addgoods";
    }

    /**
     * 获取所有的类型
     * @return
     */

    @RequestMapping("/getType")
    @ResponseBody
    public MyMessage getType() {
        MyMessage myMessage = new MyMessage();
        myMessage.setData(typeService.getAllType());
        return myMessage;

    }
}
